﻿using System.Windows;
using System.Windows.Input;
using XmlStudio.Helper;

namespace XmlStudio.Controls {

    /// <summary>
    /// Canvas on which the DesignerItems are placed.
    /// </summary>
    public partial class DesignerCanvas {
        #region Commands
        /// <summary>
        /// Select all command.
        /// </summary>
        public static RoutedCommand SelectAll = new RoutedCommand();
        #endregion

        #region Constructors
        /// <summary>
        /// Initializes a new instance of the DesignerCanvas class. Adds command bindings for itself.
        /// </summary>
        public DesignerCanvas() {
            SelectionService.Create(this);

            SelectAll.InputGestures.Add(new KeyGesture(Key.A, ModifierKeys.Control)); // ctrl+A = select all

            this.AllowDrop = true;
            Clipboard.Clear();
        }
        #endregion

        #region Helper Methods
        //private void Reset()
        //{
        //    this.Children.Clear();
        //    this.SelectionService.ClearSelection();
        //}

        //private void UpdateZIndex()
        //{
        //    List<UIElement> ordered = (from UIElement item in this.Children
        //                               orderby Canvas.GetZIndex(item as UIElement)
        //                               select item as UIElement).ToList();

        //    for (int i = 0; i < ordered.Count; i++)
        //    {
        //        Canvas.SetZIndex(ordered[i], i);
        //    }
        //}

        //private bool BelongToSameGroup(IGroupable item1, IGroupable item2)
        //{
        //    IGroupable root1 = SelectionService.GetGroupRoot(item1);
        //    IGroupable root2 = SelectionService.GetGroupRoot(item2);

        //    return (root1.ID == root2.ID);
        //}
        #endregion
    }
}